﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace robotGUI
{
    public partial class BatterySelector : UserControl
    {
        BindingList<BatterySelectorEntry> batteryList;
        [Category("Appearance"),
         DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public BindingList<BatterySelectorEntry> BatteryList
        {
            get { return batteryList; }
            set { batteryList = value; }
        }
        public BatterySelector()
        {
            InitializeComponent();
            batteryList = new BindingList<BatterySelectorEntry>();
            batteryList.ListChanged += new ListChangedEventHandler(batteryList_ListChanged);
        }

        private void BatterySelector_Load(object sender, EventArgs e)
        {
            updateDescription();
        }

        private void updateDescription()
        {
            label1.Text = batteryList[trackBar1.Value].ToString();
            label2.Text = batteryList[trackBar1.Value].MaximumVoltage.ToString("F1") + "v";
            label5.Text = batteryList[trackBar1.Value].WarningVoltage.ToString("F1") + "v";
        }

        void batteryList_ListChanged(object sender, ListChangedEventArgs e)
        {
            if (batteryList.Count > 0)
            {
                trackBar1.Maximum = batteryList.Count - 1;
            }
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            updateDescription();
        }

    }

    public class BatterySelectorEntry
    {
        string description;
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        float nominalVoltage;
        public float NominalVoltage
        {
            get { return nominalVoltage; }
            set { nominalVoltage = value; }
        }
        float maximumVoltage;
        public float MaximumVoltage
        {
            get { return maximumVoltage; }
            set { maximumVoltage = value; }
        }
        float warningVoltage;
        public float WarningVoltage
        {
            get { return warningVoltage; }
            set { warningVoltage = value; }
        }
        public BatterySelectorEntry(string description, float nominal, float maximum, float warning)
        {
            Description = description;
            NominalVoltage = nominal;
            MaximumVoltage = maximum;
            WarningVoltage = warning;
        }
        public BatterySelectorEntry() : this("New Battery", 9, 9, 7) { }
        public override string ToString()
        {
            return description + " (" + nominalVoltage.ToString("F1") + "v)";
        }
    }

}
